package com.aidl.demo.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.aidl.demo.R;
import com.aidl.demo.entity.Video;
import com.bumptech.glide.Glide;

import java.util.List;

/**
 * Created by Administrator on 2018/7/27 0027.
 */

public class MyGridViewAdapter extends BaseAdapter {
    private Context context;
    private List<Video> stringList;

    public MyGridViewAdapter(Context context, List<Video> stringList) {
        this.context = context;
        this.stringList = stringList;
    }

    @Override
    public int getCount() {
        return stringList.size() == 0 ? null : stringList.size();
    }

    @Override
    public Object getItem(int position) {
        return stringList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = View.inflate(context, R.layout.adapter_movie_list, null);
            holder.movieListImg = convertView.findViewById(R.id.movie_list_img);
            holder.movieListText = convertView.findViewById(R.id.movie_list_text);
            holder.movieListRl = convertView.findViewById(R.id.movie_list_rl);
            holder.movieListRl.setFocusable(true);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.movieListText.setText(stringList.get(position).title);
        Glide.with(context).load(stringList.get(position).coverImage).into(holder.movieListImg);
        return convertView;
    }

    class ViewHolder {
        ImageView movieListImg;
        TextView movieListText;
        RelativeLayout movieListRl;
    }
}